{% extends 'default/base.html' %}
{% load bootstrap %}
{% block content %}
<style>
    .col-sm-10 ul{list-style-type:none;line-height:33px;}
    .col-sm-10 li{float:left;margin-right:12px;text-align: left;}
    .col-sm-10 select  {
    background-color: #FFFFFF;
    background-image: none;
    border: 1px solid #CCCCCC;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
    color: #555555;
    display: block;
    font-size: 14px;
    height: 34px;
    line-height: 1.42857;
    padding: 6px 12px;
    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
    vertical-align: middle;
    width: 100%;
}
.control-label{width:100px;}
.form-control{width:100%;}
.col-sm-10 select{width:100%;}
.form-horizontal{margin-top:10px;}
*.btn-block{margin-left:100px;margin-bottom:100px;}*
.voilet_top{margin-bottom:100px;}
</style>
<div id="data_ok"></div>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>添加权限 | add auth.</h2>
    </div>
    <div class="col-lg-2">
    </div>
</div>
<div class="wrapper">
    <div class="row">
        <div class="ibox float-e-margins">
            <form class="form-horizontal col-md-12"  method="post" id="form_data">
                {% csrf_token %}
                <div class="form-group">
                    <label class="control-label col-sm-2 col-lg-2 " for="id_user_name">用户</label>
                    <div class=" col-sm-10 col-lg-10 ">
                    <input class=" form-control" type="text" value="{{ user_data.first_name }}" readonly>
                    </div>
                </div>
                {{ data|bootstrap_horizontal }}
                <div class="form-group">
                    <label class="control-label col-sm-2 col-lg-2 " for="id_user_name">选择项目</label>
                    <div class=" col-sm-10 col-lg-10 ">
                        <select class="form-control select_business" id="id_auth_weights" name="auth_weights">
                        <option value="" selected="selected">---------</option>
                        {% for k in business %}
                            <option value="{{ k.id }}">{{ k.aliases_name }}</option>
                        {% endfor %}
                            <option value="all">未分类</option>
                        </select>
                    </div>
                </div>
                <div id="edit_result"></div>

                <div class="col-sm-10 col-lg-10 voilet_top"><button href="/accounts/server/auth/add/{{ user_data.id }}/" class="btn btn-info btn-block edit-save" >保存</button></div>
                <div class="voilet_top"></div>
            </form>
        </div>
    </div>
</div>
<script>
    $(function(){
       $(document).ready(function(){
            $('.select_business').change(function() {
{#                alert($(this).val());#}
                ///assets/server/server_type/id/
                //alert({{ user_data.id }});
                var url= '/assets/server/user_auth/?id=' + $(this).val() + "&auth_id=" + {{ user_data.id }};
                if ($(this).val().length==0){alert("你想干吗");return}
                if ($(this).val() == 'all'){
                   $.ajax({
                     type: "GET",
                     url: "/assets/server/auth_without_business/?auth_id=" + "{{ user_data.id }}" }).done(function( data ) {
                     $("#edit_result").html(data);
                 });return;
                }
                 $.ajax({
                     type: "GET",
                     url: url }).done(function( data ) {
                     $("#edit_result").html(data);
                 });
            });
        });


        // 机柜位置
         $(document).ready(function(){
              $('.edit-save').click(function(){
                jQuery.ajax({
                  url: $(this).attr("href"),                  // 提交的页面
                  data: $('#form_data').serialize(), // 从表单中获取数据
                  type: "POST",                       // 设置请求类型为"POST"，默认为"GET"
                  dataType:'text',
                  success: function(msg){
                      //$("#edit_result").html(msg)
                    alert(msg);                       // 设置表单提交完成使用方法
                  }
                });
              });
              return false;
         });
     })

</script>

{% endblock content %}



